<?php


namespace app\admin\controller;


use app\BaseController;
use think\facade\Db;
use think\facade\Session;

class Login extends BaseController
{
    public function index()
    {
        if(request()->isPost()){
            $post=input('post.');
            if(!captcha_check($post['code'])){
                $this->error('验证码错误','index');
            }
            $userData=Db::name('admin')->where('name',$post['name'])->find();
            if(!$userData){
                $this->error('用户名错误','index');
            }
            if (md5('pmc'.$post['password'].'10086') !== $userData['password']){
                $this->error('密码错误','index');
            }
            Db::name('admin')->where('id',$userData['id'])->update(['addtime'=>time()]);
            session::set('IndexSessionData',$userData);
            //$this->success('','/index');
            $this->redirect('/admin.php/index/index');
        }else{
            // $this->error('登录失败，请从新登录','Login/index');
            return view();
        }

    }
    public function loginout(){
        //session::get('IndexSessionData');
        //session::delete('IndexSessionData');
        session::clear();
        $this->success('退出完成','/admin.php/Login/index');
    }

}
